{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4e1dfaca",
   "metadata": {},
   "source": [
    "* 2022/9/19 week5\n",
    "* python学习记录"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6dc0425",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1.控制流\n",
    ">> 1. 条件判断\n",
    ">> 2. 循环遍历\n",
    "\n",
    "> 2. 随机函数\n",
    "> 3. 时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41cbd9a0",
   "metadata": {},
   "source": [
    "# 1.控制流\n",
    "## 1.条件判断\n",
    "* 知识点\n",
    ">1. 赋值 是“= ”\n",
    ">2. 判断是否两者相等是“==”\n",
    ">3. 代码中出现的变量，必须先定义，否则： name变量名 is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "39783a66",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (3012814007.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn [1], line 5\u001b[1;36m\u001b[0m\n\u001b[1;33m    else:\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "if today == \"saterday\":\n",
    "    print(\"Party\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition ==\"Headache\":\n",
    "    else:\n",
    "        print(\"Rest\")\n",
    "else:\n",
    "    print(\"Work,work,work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "57dc78e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Party\n"
     ]
    }
   ],
   "source": [
    "# 先定义变量 today\n",
    "\n",
    "today = \"Saturday\"\n",
    "if today ==\"Saturday\":\n",
    "    print(\"Party\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "31a044fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work, work, work.\n"
     ]
    }
   ],
   "source": [
    "today = \"Monday\"\n",
    "condition = \"Headache\"\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "272f0a67",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 关于if else条件判断实践:\n",
    "## 请判断今天是周几，如果是周一，有python课，好开心呀，如果不是，期待周一呀。（time可以帮我们知道今天是周几）\n",
    "##                        如果是周一，请判断现在是否正在上python课，（time可以帮我们知道现在是几点钟几分钟）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f208b372",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e7338ede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=20, tm_hour=15, tm_min=28, tm_sec=15, tm_wday=3, tm_yday=293, tm_isdst=0)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "164e5cf9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "91546824",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 3\n",
      "几点 15\n",
      "几分 47\n",
      "期待周一呀\n"
     ]
    }
   ],
   "source": [
    "#  tm_day  0-6   0 是周一\n",
    "# 准备工作：准备所有可能用到的变量\n",
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min =  time.localtime().tm_min\n",
    "print(\"几分\",today_min)\n",
    "# 条件判断，完成：\n",
    "## 关于if else条件判断实践：\n",
    "## 请判断今天是周几，如果是周一，有Python课，好开心呀。如果不是，期待周一呀。（time可以帮我们知道今天周几）\n",
    "##                      如果是周一，请判断现在是否正在上python课。（time可以帮我们知道现在是几点钟几分钟）\n",
    "\n",
    "if wday == 0:\n",
    "    print(\"今天是周一，有Python课，好开心呀~\")\n",
    "    if 9 < today_hour < 12:\n",
    "        print(\"现在是\",today_hour,\"点\",today_min,\"分\",\"正在上 Python\")\n",
    "    elif today_hour == 9:\n",
    "        if today_min >= 45:\n",
    "            print(\"正在上 Python\")\n",
    "        elif today_min == 30:\n",
    "            print(\"手机弹出框，还有15分钟要上Python课了，请提前准备好课本和电脑，检查好电量！\")\n",
    "        else:\n",
    "            print(\"马上就要上Python了，好激动呀~\")\n",
    "    else:\n",
    "        print(\"没在上Python\")\n",
    "else:\n",
    "    print(\"期待周一呀\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c18a5001",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93b61a9e",
   "metadata": {},
   "source": [
    "# 2. 循环遍历（for）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "75a55cc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in[1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ac1efec2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "eaf7da9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上述 i 和 ch 都是变量，可以根据我们的需求定义变量名\n",
    "# 每一次执行，赋值一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "cdc156db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "# range(): 范围，区间\n",
    "for num in range(10):\n",
    "    print('hello world!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "67e54500",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.range()是一个数字/数值生成器，默认每次增加1\n",
    "# 2.range()包含有 起始点start（默认为0） 终止点stop 以及步长step（默认为i）\n",
    "range(5)# 默认的起点 是 0 ，终结点 5 产生了 5 - 0 个数值， 默认每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c256129e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3bf1fe9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(5, 10)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5,10) # 自定义起始点 5,终结点 10 产生了 10 - 5个数值，默认每次增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "655d4363",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "83ef17f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10, 3)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0, 10, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2b7d8ce6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0, 10, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "09e52e8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 请参考以下，获取广州南方学院"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7003b4f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/xxyw/index0.htm\n",
      "https://www.nfu.edu.cn/xxyw/index1.htm\n",
      "https://www.nfu.edu.cn/xxyw/index2.htm\n",
      "https://www.nfu.edu.cn/xxyw/index3.htm\n",
      "https://www.nfu.edu.cn/xxyw/index4.htm\n",
      "https://www.nfu.edu.cn/xxyw/index5.htm\n",
      "https://www.nfu.edu.cn/xxyw/index6.htm\n",
      "https://www.nfu.edu.cn/xxyw/index7.htm\n",
      "https://www.nfu.edu.cn/xxyw/index8.htm\n",
      "https://www.nfu.edu.cn/xxyw/index9.htm\n",
      "https://www.nfu.edu.cn/xxyw/index10.htm\n",
      "https://www.nfu.edu.cn/xxyw/index11.htm\n",
      "https://www.nfu.edu.cn/xxyw/index12.htm\n",
      "https://www.nfu.edu.cn/xxyw/index13.htm\n",
      "https://www.nfu.edu.cn/xxyw/index14.htm\n",
      "https://www.nfu.edu.cn/xxyw/index15.htm\n",
      "https://www.nfu.edu.cn/xxyw/index16.htm\n",
      "https://www.nfu.edu.cn/xxyw/index17.htm\n",
      "https://www.nfu.edu.cn/xxyw/index18.htm\n",
      "https://www.nfu.edu.cn/xxyw/index19.htm\n",
      "https://www.nfu.edu.cn/xxyw/index20.htm\n",
      "https://www.nfu.edu.cn/xxyw/index21.htm\n",
      "https://www.nfu.edu.cn/xxyw/index22.htm\n",
      "https://www.nfu.edu.cn/xxyw/index23.htm\n",
      "https://www.nfu.edu.cn/xxyw/index24.htm\n",
      "https://www.nfu.edu.cn/xxyw/index25.htm\n",
      "https://www.nfu.edu.cn/xxyw/index26.htm\n",
      "https://www.nfu.edu.cn/xxyw/index27.htm\n",
      "https://www.nfu.edu.cn/xxyw/index28.htm\n",
      "https://www.nfu.edu.cn/xxyw/index29.htm\n",
      "https://www.nfu.edu.cn/xxyw/index30.htm\n",
      "https://www.nfu.edu.cn/xxyw/index31.htm\n",
      "https://www.nfu.edu.cn/xxyw/index32.htm\n",
      "https://www.nfu.edu.cn/xxyw/index33.htm\n",
      "https://www.nfu.edu.cn/xxyw/index34.htm\n",
      "https://www.nfu.edu.cn/xxyw/index35.htm\n",
      "https://www.nfu.edu.cn/xxyw/index36.htm\n",
      "https://www.nfu.edu.cn/xxyw/index37.htm\n",
      "https://www.nfu.edu.cn/xxyw/index38.htm\n",
      "https://www.nfu.edu.cn/xxyw/index39.htm\n",
      "https://www.nfu.edu.cn/xxyw/index40.htm\n",
      "https://www.nfu.edu.cn/xxyw/index41.htm\n",
      "https://www.nfu.edu.cn/xxyw/index42.htm\n",
      "https://www.nfu.edu.cn/xxyw/index43.htm\n",
      "https://www.nfu.edu.cn/xxyw/index44.htm\n",
      "https://www.nfu.edu.cn/xxyw/index45.htm\n",
      "https://www.nfu.edu.cn/xxyw/index46.htm\n",
      "https://www.nfu.edu.cn/xxyw/index47.htm\n",
      "https://www.nfu.edu.cn/xxyw/index48.htm\n",
      "https://www.nfu.edu.cn/xxyw/index49.htm\n",
      "https://www.nfu.edu.cn/xxyw/index50.htm\n",
      "https://www.nfu.edu.cn/xxyw/index51.htm\n",
      "https://www.nfu.edu.cn/xxyw/index52.htm\n",
      "https://www.nfu.edu.cn/xxyw/index53.htm\n",
      "https://www.nfu.edu.cn/xxyw/index54.htm\n",
      "https://www.nfu.edu.cn/xxyw/index55.htm\n",
      "https://www.nfu.edu.cn/xxyw/index56.htm\n",
      "https://www.nfu.edu.cn/xxyw/index57.htm\n",
      "https://www.nfu.edu.cn/xxyw/index58.htm\n",
      "https://www.nfu.edu.cn/xxyw/index59.htm\n",
      "https://www.nfu.edu.cn/xxyw/index60.htm\n",
      "https://www.nfu.edu.cn/xxyw/index61.htm\n",
      "https://www.nfu.edu.cn/xxyw/index62.htm\n",
      "https://www.nfu.edu.cn/xxyw/index63.htm\n",
      "https://www.nfu.edu.cn/xxyw/index64.htm\n",
      "https://www.nfu.edu.cn/xxyw/index65.htm\n",
      "https://www.nfu.edu.cn/xxyw/index66.htm\n",
      "https://www.nfu.edu.cn/xxyw/index67.htm\n",
      "https://www.nfu.edu.cn/xxyw/index68.htm\n",
      "https://www.nfu.edu.cn/xxyw/index69.htm\n",
      "https://www.nfu.edu.cn/xxyw/index70.htm\n",
      "https://www.nfu.edu.cn/xxyw/index71.htm\n",
      "https://www.nfu.edu.cn/xxyw/index72.htm\n",
      "https://www.nfu.edu.cn/xxyw/index73.htm\n",
      "https://www.nfu.edu.cn/xxyw/index74.htm\n",
      "https://www.nfu.edu.cn/xxyw/index75.htm\n",
      "https://www.nfu.edu.cn/xxyw/index76.htm\n",
      "https://www.nfu.edu.cn/xxyw/index77.htm\n",
      "https://www.nfu.edu.cn/xxyw/index78.htm\n",
      "https://www.nfu.edu.cn/xxyw/index79.htm\n",
      "https://www.nfu.edu.cn/xxyw/index80.htm\n",
      "https://www.nfu.edu.cn/xxyw/index81.htm\n",
      "https://www.nfu.edu.cn/xxyw/index82.htm\n",
      "https://www.nfu.edu.cn/xxyw/index83.htm\n",
      "https://www.nfu.edu.cn/xxyw/index84.htm\n",
      "https://www.nfu.edu.cn/xxyw/index85.htm\n",
      "https://www.nfu.edu.cn/xxyw/index86.htm\n",
      "https://www.nfu.edu.cn/xxyw/index87.htm\n",
      "https://www.nfu.edu.cn/xxyw/index88.htm\n",
      "https://www.nfu.edu.cn/xxyw/index89.htm\n",
      "https://www.nfu.edu.cn/xxyw/index90.htm\n",
      "https://www.nfu.edu.cn/xxyw/index91.htm\n",
      "https://www.nfu.edu.cn/xxyw/index92.htm\n",
      "https://www.nfu.edu.cn/xxyw/index93.htm\n",
      "https://www.nfu.edu.cn/xxyw/index94.htm\n",
      "https://www.nfu.edu.cn/xxyw/index95.htm\n",
      "https://www.nfu.edu.cn/xxyw/index96.htm\n",
      "https://www.nfu.edu.cn/xxyw/index97.htm\n",
      "https://www.nfu.edu.cn/xxyw/index98.htm\n",
      "https://www.nfu.edu.cn/xxyw/index99.htm\n",
      "https://www.nfu.edu.cn/xxyw/index100.htm\n",
      "https://www.nfu.edu.cn/xxyw/index101.htm\n",
      "https://www.nfu.edu.cn/xxyw/index102.htm\n",
      "https://www.nfu.edu.cn/xxyw/index103.htm\n",
      "https://www.nfu.edu.cn/xxyw/index104.htm\n",
      "https://www.nfu.edu.cn/xxyw/index105.htm\n",
      "https://www.nfu.edu.cn/xxyw/index106.htm\n",
      "https://www.nfu.edu.cn/xxyw/index107.htm\n",
      "https://www.nfu.edu.cn/xxyw/index108.htm\n",
      "https://www.nfu.edu.cn/xxyw/index109.htm\n"
     ]
    }
   ],
   "source": [
    "# 实践： 数据挖掘---获取页面/URL队列\n",
    "学校要闻 = \"xxyw\"\n",
    "学校要闻_page = 110\n",
    "\n",
    "for page in range(学校要闻_page):\n",
    "    print(\"https://www.nfu.edu.cn/\" + 学校要闻 + \"/index\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "554a452d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
